
package com.xbongbong.paas.domain.entity;

import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.Entity;
import com.xbongbong.pro.constant.I18nStringConstant;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Locale;
import java.util.Objects;

/**
* @author autoGen
* @time 2018-08-13 09:59:18
 *
 * 修改时间： 2019-1-10 19:53 何卡特 get/set方法改用lombok实现
*/
@Getter
@Setter
@ToString
public class PaasFormEntity extends Entity {

	/** Comment for <code>serialVersionUID</code> */
	private static final long serialVersionUID = -2215954328120924367L;

	//========== properties ==========

	/**
	* 主键
	*/
	private Long id;
	/**
	* 公司id
	*/
	private String corpid;
	/**
	* 应用id
	*/
	private Long appId;
	/**
	* 菜单id
	*/
	private Long menuId;
	/**
	 * 表单名称
	 */
	private String name;

	/**
	 * 表单名称英文版
	 */
	private String nameEn;
	/**
	 * saas标记
	 */
	private Integer saasMark;
	/**
	 * 业务类型
	 */
	private Integer businessType;
	/**
	 * 启用
	 */
	private Integer enable;
	/**
	* 是否流程表单，1是，0否
	*/
	private Integer isProcessForm;
	/**
	* 表单验证规则
	*/
	private String verifyRule;
	/**
	* 不可见字段赋值，1 保持原值，2 空值，3 始终重新计算
	*/
	private Integer disableFieldAssign;
	/**
	* 前端缓存，1 启用，0 禁用
	*/
	private Integer frontCache;
	/**
	* 数据标题类型，1第一个字段，2自定义标题
	*/
	private Integer titleType;
	/**
	* 自定义标题，具体指定格式
	*/
	private String customTitle;

	/**
	 * 关联列表设置
	 */
	private String associationList;
	/**
	 *  业务规则
	 */
	private String businessRules;
	/**
	 * 费用
	 */
	private String surcharge;
	/**
	 * 是否开启业绩分配
	 */
	private Integer openDistribution;
	/**
	 * 销售价格关联，用于出库单；1：开启；0：不开启
	 */
	private Integer priceAssociation;
	/**
	* 自定义摘要，具体指定格式, 用于手机端列表页显示
	*/
	private String summary;
	/**
	 * 标签列表，最多5个字段
	 */
	private String labels;
	/**
	* 协同人权限设置
	*/
	private String coOpPerms;
	/**
	* 使用权限设置
	*/
	private String permission;
	/**
	* 创建者id
	*/
	private String creatorId;
	/**
	* 创建时间时间戳
	*/
	private Long addTime;
	/**
	* 更新时间时间戳
	*/
	private Long updateTime;
	/**
	* 删除标记
	*/
	private Integer del;

	/**
	 * 钉钉待办模板code
	 */
	private String dingtalkProcessCode;
	/**
	 * 镜像表单id(镜像应用复制时使用)
	 */
	private Long mirrorFormId;
	/**
	 * 镜像应用id
	 */
	private Long mirrorAppId;
	/**
	 * 镜像菜单id
	 */
	private Long mirrorMenuId;

	/**
	 * 表单排序值
	 */
	private Integer sort;

	/**
	 * 表单内所有字段名的分布  'left' 和 'top'
	 */
	private String fieldPosition;


	private Integer distributorMark;

	private Integer hidden;

	/**
	 * 产品子表单主业务formId，主要用于产品子表单数据迁移，并不入库
	 */
	private Long subProductMainFormId;

	/**
	 * 产品子表单类型，主要用于产品子表单数据迁移，并不入库
	 */
	private Integer subProductType;

	public PaasFormEntity(){
		del = 0;
	}

	public PaasFormEntity(String corpid, Long appId, Long menuId, String name, Integer saasMark, Integer businessType, Integer enable, Integer isProcessForm, String verifyRule, Integer disableFieldAssign, Integer frontCache, Integer titleType, String customTitle, String associationList, String businessRules, String surcharge, Integer openDistribution, Integer priceAssociation, String summary, String labels, String coOpPerms, String permission, String creatorId, Long addTime, Long updateTime, Integer del, String fieldPosition, Integer hidden, Integer distributorMark) {
		this.corpid = corpid;
		this.appId = appId;
		this.menuId = menuId;
		this.name = name;
		this.saasMark = saasMark;
		this.businessType = businessType;
		this.enable = enable;
		this.isProcessForm = isProcessForm;
		this.verifyRule = verifyRule;
		this.disableFieldAssign = disableFieldAssign;
		this.frontCache = frontCache;
		this.titleType = titleType;
		this.customTitle = customTitle;
		this.associationList = associationList;
		this.businessRules = businessRules;
		this.surcharge = surcharge;
		this.openDistribution = openDistribution;
		this.priceAssociation = priceAssociation;
		this.summary = summary;
		this.labels = labels;
		this.coOpPerms = coOpPerms;
		this.permission = permission;
		this.creatorId = creatorId;
		this.addTime = addTime;
		this.updateTime = updateTime;
		this.del = del;
		this.fieldPosition = fieldPosition;
		this.hidden =hidden;
		this.distributorMark=distributorMark;
	}


	public PaasFormEntity(String corpid, Long appId, Long menuId, String name, Integer saasMark, Integer businessType, Integer enable, Integer isProcessForm, String verifyRule, Integer disableFieldAssign, Integer frontCache, Integer titleType, String customTitle, String associationList, String businessRules,  String summary, String fieldPosition, Integer distributorMark) {
		this.corpid = corpid;
		this.appId = appId;
		this.menuId = menuId;
		this.name = name;
		this.saasMark = saasMark;
		this.businessType = businessType;
		this.enable = enable;
		this.isProcessForm = isProcessForm;
		this.verifyRule = verifyRule;
		this.disableFieldAssign = disableFieldAssign;
		this.frontCache = frontCache;
		this.titleType = titleType;
		this.customTitle = customTitle;
		this.associationList = associationList;
		this.businessRules = businessRules;
		this.summary = summary;
		this.fieldPosition = fieldPosition;
		this.distributorMark=distributorMark;
	}

	public PaasFormEntity(Long id, Long appId, Long menuId, Integer saasMark, Integer businessType) {
		this.id = id;
		this.appId = appId;
		this.menuId = menuId;
		this.saasMark = saasMark;
		this.businessType = businessType;
	}

	public String getName() {
		Locale locale = LocaleContextHolder.getLocale();
		if (Objects.equals(locale.getLanguage(), I18nStringConstant.ENGLISH_LANGUAGE)&& StringUtil.isNotEmpty(nameEn)) {
			return nameEn;
		}
		return name;
	}

	public String getNameEn() {
		Locale locale = LocaleContextHolder.getLocale();
		if (Objects.equals(locale.getLanguage(), I18nStringConstant.ENGLISH_LANGUAGE)) {
			return name;
		}
		return nameEn;
	}
}

